local lianke = fk.CreateSkill{
  name = "hanqing__lianke",
}

Fk:loadTranslationTable{
  ["hanqing__lianke"] = "连克",
  [":hanqing__lianke"] = "出牌阶段每个牌名限一次，你可以将一张牌当【火攻】、【出其不意】或【兵临城下】使用，若因此造成伤害，"..
  "将展示或亮出牌加入此阶段下次因此展示或亮出的牌中，超过五张后，你令一名角色使用其中一张牌。",

  ["#hanqing__lianke"] = "连克：将一张牌当【火攻】、【出其不意】或【兵临城下】使用",
  ["#hanqing__lianke-choose"] = "连克：令一名角色使用其中一张牌",
  ["#hanqing__lianke-use"] = "连克：使用其中一张牌",
}

lianke:addEffect("viewas", {
  anim_type = "offensive",
  mute_card = false,
  prompt = "#hanqing__lianke",
  interaction = function(self, player)
    local all_names = { "fire_attack", "unexpectation", "enemy_at_the_gates" }
    local names = player:getViewAsCardNames(lianke.name, all_names, nil, player:getTableMark("hanqing__lianke-phase"))
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  handly_pile = true,
  card_filter = function (self, player, to_select, selected)
    return #selected == 0
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 or self.interaction.data == nil then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = lianke.name
    card:addSubcards(cards)
    return card
  end,
  before_use = function (self, player, use)
    local room = player.room
    room:addTableMark(player, "hanqing__lianke-phase", use.card.name)
    local card = use.card:clone()
    local c = table.simpleClone(use.card)
    for k, v in pairs(c) do
      card[k] = v
    end
    card.skill = Fk.skills["hanqing__lianke__"..self.interaction.data.."_skill"]
    use.card = card
  end,
  after_use = function (self, player, use)
    local room = player.room
    local cards = room:getBanner("hanqing__lianke-phase") or {}
    if not player.dead and #cards > 4 then
      local to = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = room.alive_players,
        skill_name = lianke.name,
        prompt = "#hanqing__lianke-choose",
        cancelable = false,
      })[1]
      room:askToUseRealCard(to, {
        pattern = cards,
        skill_name = lianke.name,
        prompt = "#hanqing__lianke-use",
        extra_data = {
          bypass_times = true,
          expand_pile = cards,
        },
        cancelable = false,
      })
    end
  end,
  enabled_at_play = function (self, player)
    return #player:getTableMark("hanqing__lianke-phase") < 3
  end,
})

lianke:addAI(nil, "vs_skill")

return lianke
